package com.neighbor.spring.mysql;

import com.alibaba.druid.pool.DruidDataSource;
import com.neighbor.spring.core.SpringApplicationContext;

import java.util.Random;

/**
 * @author ysw
 * @create 2019-04-22 15:08
 * @descreption
 **/
public class Jdbc {


    public static JdbcOperation build() {
        return new JdbcOperation(SpringApplicationContext.getBean("dataSource"));
    }

    public static JdbcOperation buildRead() {
        DataSourceList dataSourceList = SpringApplicationContext.getBean("dataSourceList");
        Random random = new Random();
        int i = random.nextInt(dataSourceList.getList().size());
        return new JdbcOperation(dataSourceList.getList().get(i));
    }


    public static JdbcOperation build(DruidDataSource dataSource) {
        return new JdbcOperation(dataSource);
    }


    public static JdbcOperation build(String tableName) {
        return new JdbcOperation(SpringApplicationContext.getBean("dataSource"), tableName);
    }

    public static JdbcOperation build(DruidDataSource dataSource, String tableName) {
        return new JdbcOperation(dataSource, tableName);
    }


}
